﻿using System;
using System.Linq;

namespace BITS.PreCompiler.CSharp.Syntax.Extensions
{
    /// <summary>
    /// Extension methods for <see cref="Module"/>.
    /// </summary>
    public static class ModuleExtension
    {
        /// <summary>
        /// Gets the class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <returns></returns>
        public static Class GetFirstClass(this Module module)
        {
            if (module.Namespace == null)
                throw new ApplicationException("Namespace is required!");

            var @namespace = module.Namespace;

            if (!@namespace.Classes.Any())
                throw new ApplicationException("At least one class is required!");

            return @namespace.Classes.First();
        }
    }
}
